package cn.gson.springboot.model.service;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.mysql.cj.xdevapi.JsonArray;

import cn.gson.springboot.model.dao.ArrangeClassDAO;
import cn.gson.springboot.model.dao.ArrangeClassPxDAO;
import cn.gson.springboot.model.dao.CureCostPxDAO;
import cn.gson.springboot.model.dao.CurePxDAO;
import cn.gson.springboot.model.dao.DepartmentsDAO;
import cn.gson.springboot.model.dao.DrugsYkDao;
import cn.gson.springboot.model.dao.ExamineDAO;
import cn.gson.springboot.model.dao.ExamineItemDAO;
import cn.gson.springboot.model.dao.ExamineRecordDAO;
import cn.gson.springboot.model.dao.GhlxDAO;
import cn.gson.springboot.model.dao.HospitalnoticeDAO;
import cn.gson.springboot.model.dao.MedicalCardDAO;
import cn.gson.springboot.model.dao.MedicalNoticeDAO;
import cn.gson.springboot.model.dao.MedicalNoticexqPxDAO;
import cn.gson.springboot.model.dao.MzcostDetailDAO;
import cn.gson.springboot.model.dao.MzcostDetailsRecordDAO;
import cn.gson.springboot.model.dao.OutpatientrecordsDAO;
import cn.gson.springboot.model.dao.PrescriptionDAO;
import cn.gson.springboot.model.dao.PrescriptionDetailsPxDAO;
import cn.gson.springboot.model.dao.RegisteredDAO;
import cn.gson.springboot.model.dao.TjsfjlbTDAO;
import cn.gson.springboot.model.dao.UserDAO;
import cn.gson.springboot.model.dao.YfChangerDAO;

import cn.gson.springboot.model.mapper.ExamineMapper;
import cn.gson.springboot.model.mapper.ArrangeClassesMapper;
import cn.gson.springboot.model.mapper.ArrangeclassMapper;
import cn.gson.springboot.model.mapper.CureCostMapper;
import cn.gson.springboot.model.mapper.CureMapper;
import cn.gson.springboot.model.mapper.DepartmentsMapper;
import cn.gson.springboot.model.mapper.DrugrefundRecordtbPxMapper;
import cn.gson.springboot.model.mapper.GhlxMapper;
import cn.gson.springboot.model.mapper.MedicalNoticeMapper;
import cn.gson.springboot.model.mapper.MzcostDetailsRecordMapper;
import cn.gson.springboot.model.mapper.OutpatientRecordsMapper;
import cn.gson.springboot.model.mapper.PrescriptionPXMapper;
import cn.gson.springboot.model.mapper.TjsfjlbTMapper;
import cn.gson.springboot.model.mapper.UserMapper;
import cn.gson.springboot.model.mapper.YfchangerMapper;
import cn.gson.springboot.model.pojos.ArrangeClass;
import cn.gson.springboot.model.pojos.ArrangeClassPx;
import cn.gson.springboot.model.pojos.CureCostPx;
import cn.gson.springboot.model.pojos.CurePx;
import cn.gson.springboot.model.pojos.DepartmentsPx;
import cn.gson.springboot.model.pojos.DrugsYk;
import cn.gson.springboot.model.pojos.Examine;
import cn.gson.springboot.model.pojos.ExamineItem;
import cn.gson.springboot.model.pojos.ExamineRecord;
import cn.gson.springboot.model.pojos.GhlxPx;
import cn.gson.springboot.model.pojos.HospitalNotice;
import cn.gson.springboot.model.pojos.MedicalCardPx;
import cn.gson.springboot.model.pojos.MzcostDetail;
import cn.gson.springboot.model.pojos.MzcostDetailsRecordPx;
import cn.gson.springboot.model.pojos.OutpatientRecord;
import cn.gson.springboot.model.pojos.PrescriptionDetailsPx;
import cn.gson.springboot.model.pojos.PrescriptionPx;
import cn.gson.springboot.model.pojos.RegisteredPx;
import cn.gson.springboot.model.pojos.TjsfjlbTbPx;
import cn.gson.springboot.model.pojos.User;
import cn.gson.springboot.model.pojos.YfChangerPx;
import cn.gson.springboot.model.vo.CurecostVO;
import cn.gson.springboot.model.vo.ExamineVO;
import cn.gson.springboot.model.vo.PrescriptionVO;
@Service
@Transactional(rollbackFor=Exception.class)
public class Ghlxserivce {
	
	@Autowired
	private  CureMapper  curemp;
	//排班mapper
	@Autowired
	private ArrangeclassMapper  arrmapper;
	//科室mapper
	@Autowired
	private  DepartmentsMapper deptmapper;
	//排班DAO
	@Autowired
	private ArrangeClassPxDAO arrdao;
	//排次DAO
	@Autowired
	private  ArrangeClassDAO  adao;
	//用户mapper
	@Autowired
	private  UserMapper ump; 
	
	//班次mapper
	@Autowired
	private ArrangeClassesMapper arrmp;
	//住院通知DAO
	@Autowired
	private HospitalnoticeDAO hdao;
	
	//退药记录mapper
	@Autowired
	private DrugrefundRecordtbPxMapper tfjlmp;
	
	
	@Autowired
	private MedicalCardDAO ylkdao;//医疗卡dao
	@Autowired
	private GhlxMapper  gmp;
	
	@Autowired
	private GhlxDAO  gdao;
	
	//医疗项目费用到
	@Autowired
	private  CureCostPxDAO  curedao;
	
	//医疗项目费用详表到
	@Autowired
	private  MzcostDetailDAO  xmxqcost;
	
	//体检项目通知主表dao
	@Autowired
	private MedicalNoticeDAO  mndao;
	
	//体检项目通知详表表dao
	@Autowired 
	private MedicalNoticexqPxDAO mnxqdao;
	
	//医疗项目dao
	@Autowired
	private  CurePxDAO  curepsdao;
	
	//收费记录Dao
	@Autowired
	private MzcostDetailsRecordDAO  mdao;
	
	//体检项目Mapper
	@Autowired
	private  ExamineMapper em;
	
	//体检项目DAO
	@Autowired
	private  ExamineItemDAO edao;
	
	//门诊药方主表DAO
	@Autowired
	private  PrescriptionDAO pdao;
	
	//门诊药方详表DAO
	@Autowired
	private PrescriptionDetailsPxDAO psdao;
	
	//药品DAO
	@Autowired
	private  DrugsYkDao  drugdao;
	
	//用户DAO
	@Autowired
	private  UserDAO  userdao;
	
	//科室DAO
	@Autowired
	private  DepartmentsDAO  ksdao;
	
	//挂号类型dao
	@Autowired
	private  GhlxDAO  ghdao;
	

	//挂号记录dao
	@Autowired
	private  RegisteredDAO  regdao;

	//医疗卡dao
	@Autowired
	private  OutpatientrecordsDAO outdao;
	
	//病历dao
	@Autowired
	private  MedicalCardDAO meddao;
	
	//门诊药方mapper
	@Autowired
	private  PrescriptionPXMapper prmapper;
	
	//挂号记录mapper
	@Autowired
	private OutpatientRecordsMapper outm;
	
	//体检费用mapper
	@Autowired
	private MedicalNoticeMapper tjmapper;
	
	
	//药方收费记录dao
	@Autowired
	private YfChangerDAO yfdao;
	
	//体检收费记录
	@Autowired
	private TjsfjlbTDAO tjdao;
	
					

	//药方收费记录mapper
	@Autowired
	private YfchangerMapper yfmapper;
	
	//体检收费记录mapper  MzcostDetailsRecordMapper
	@Autowired
	private TjsfjlbTMapper tjsfmapper;
	
	//体检收费记录mapper  MzcostDetailsRecordMapper
	@Autowired
	private MzcostDetailsRecordMapper xmmapper;
	@Autowired
	private ExamineDAO examdao;//体检登记dao
	//医疗项目mapper
	
	@Autowired
	private ExamineRecordDAO erdao;//体检记录dao ExamineMapper
	@Autowired
	private CureCostMapper cmapper;
	
	@Autowired
	private ExamineMapper emmpar;
	
		
	//查询所有挂红类型
	public JSONArray finghlx(){
		return gmp.finghlx();
	}
	
	//根据挂号类型id查询挂号金额
	public JsonArray idghje(Integer ghlx_id){
		return gmp.idghje(ghlx_id);
	}
	
	//根据挂号id查询实体
	public GhlxPx idcgh(Integer ghlx_id) {
		GhlxPx idcgh = gdao.idcgh(ghlx_id);
		return idcgh;
	}
	
	//查看所有体检项目
	public JSONArray findexamin(String ex) {
		if(ex!=null) {
			return em.findexamin("%"+ex+"%");
		}
		return em.findexamin(null);
	}
	
	// 根据名字查询体检项目
	public  JSONArray tiJianName(String examine_item_name) {
			JSONArray tiJianName = em.tiJianName(examine_item_name);
			return tiJianName;
	}
	
	//门诊药方主从表添加
	public  void  addyf(PrescriptionVO po,String userName) {
				PrescriptionPx pre = po.getPre();//得到药方主表
				pre.setPrescribing_date(new Date());
				pre.setPrescriptionState(0);//0代表未交费
				pre.setPrescriptionName(userName);
				PrescriptionPx addPrescriptionPx = pdao.save(pre);
				
				List<PrescriptionDetailsPx> pres = po.getPres();//vo类点出药方详表集合
				for (PrescriptionDetailsPx prescriptionDetailsPx : pres){
					prescriptionDetailsPx.setPrescriptionPx(addPrescriptionPx);
					DrugsYk findIDdrug = drugdao.findById(prescriptionDetailsPx.getDrugsYk().getDrugId()).get();	
					prescriptionDetailsPx.setDrugsYk(findIDdrug);
					psdao.save(prescriptionDetailsPx);
				}		
	}
	
	//医疗项目主从表新增
	public void addysxm(CurecostVO vo,String userName) {
				//项目主表实体==用vo类点出来
				CureCostPx crue=vo.getCus();
				crue.setXmys(userName);
				crue.setProjectDate(new Date());
				crue.setSfjf(1);//一代表未交费
				CureCostPx addCureCostPx=curedao.save(crue);//把vo类得到的实体新增
				List<MzcostDetail> xcus = vo.getXcus();//得到vo类中详表集合
				for (MzcostDetail mzcostDetail : xcus) {
					//添加主表编号
					mzcostDetail.setCureCostPx(crue);
					//查询项目
					CurePx findId =curepsdao.findById(mzcostDetail.getCurePx().getCureId()).get();
					mzcostDetail.setCurePx(findId);
					xmxqcost.save(mzcostDetail);
				}
		
	} 
	/*
	//新增体检项目主从表
	public void addylxm(MedicalNoticeVO mo) {
				MedicalNoticePx med = mo.getMed();//用vo类点出主表实体
					med.setMedicalNoticeState(1);//一代表为缴费
					med.setTjys("华佗");
					med.setMedicalNoticeDate(new Date());
					MedicalNoticePx addMedicalNotice = mndao.save(med);
					List<MedicalNoticexqPx> meds = mo.getMeds();//用vo类点出详表实体
					for (MedicalNoticexqPx medicalNoticexqPx : meds) {
							//添加添加通知主表编号
							medicalNoticexqPx.setMedicalNoticePx(med);
							ExamineItem findid = edao.findById(medicalNoticexqPx.getExamineItem().getExamineItemId()).get();
							medicalNoticexqPx.setExamineItem(findid);
							mnxqdao.save(medicalNoticexqPx);
					}
		
		
	}
	*/
	
	
	
		//新增体检
		public void addExamineR(ExamineVO xo){
			Examine ex = new Examine();
			ex.setExamineTime(new Timestamp(new Date().getTime()));
			ex.setExamineState("0");
			ex.setMedicalCardPx(xo.getMc());
			examdao.save(ex);
			for (ExamineItem item : xo.getItems()) {
				ExamineRecord er = new ExamineRecord();
				er.setExamine(ex);
				er.setExamineItem(item);
				erdao.save(er);
			}
		}
	
	//新增挂号记录
	public String addregistered(String mecardNumber,Integer userId,BigDecimal kzfy
				,BigDecimal ghlx_money,Integer departments_id,Integer ghlx_id,BigDecimal ghzj,
				BigDecimal ghzl,BigDecimal ghss,String userName){
			//得到用户实体
			User iduser = userdao.findById(userId).get();
			if(iduser!=null){
				//得到科室实体
				DepartmentsPx idkeshi =ksdao.findById(departments_id).get(); 
				//得到挂号实体
				GhlxPx gh=ghdao.findById(ghlx_id).get();
				//得到医疗卡实体
				MedicalCardPx idc =meddao.khchak(mecardNumber);
				RegisteredPx  px=new RegisteredPx();
				px.setGhblr(userName);
				px.setKzfy(kzfy);
				px.setGhzj(ghzj);
				px.setGhss(ghss);
				px.setGhzl(ghzl);
				px.setUser(iduser);
				px.setDepartmentsPx(idkeshi);
				px.setGhlxPx(gh);
				px.setMedicalCardPx(idc);
				px.setRegistrationDate(new Date());
				px.setGhzt(new BigDecimal(1));//1代表未接诊
				px.setRegistrationMoney(ghlx_money);
				regdao.save(px);
				return "1";
			}else {
				return "0";
			}
			
			
		}
	
	//门诊病历新增====
	public String  addbl(Integer outpatient_id, String medical_symptoms,
			BigDecimal medical_weight,BigDecimal medical_temperature,String medical_disease,String userName) {
				RegisteredPx registeredPx = regdao.findById(outpatient_id).get();
				if(registeredPx!=null){
				OutpatientRecord addbl=new OutpatientRecord();
				//addbl.setSickDate(new Date());//发病日期
				addbl.setMedicalWeight(medical_weight);//体重
				addbl.setMedicalTemperature(medical_temperature);//体温
				addbl.setMedicalSymptoms(medical_symptoms);
				addbl.setDoctorDate(new Date());//看诊日期
				addbl.setGenerateDate(new Date());//病历本办理日期
				addbl.setMedicalDisease(medical_disease); 
				addbl.setRegisteredPx(registeredPx);
				addbl.setBlys(userName);
				outdao.save(addbl);
					return "1";
				}else {
					return "0";
				}
	}
	
	//查看所有病历记录
	public JSONArray findout() {
		JSONArray findout = outm.findout();
		return findout;
	}
	//根据医疗卡门诊号查询病历
	public JSONArray medfindout(String mecard_number) {
		JSONArray medfindout = outm.medfindout(mecard_number);
		return medfindout;
	}
	
	
	//查询所有未交费的门诊药方
	public  JSONArray findwjf() {
		JSONArray findwjf = prmapper.findwjf();
		return findwjf;
	}
	
	//查询所有以交费的门诊药方
	public  JSONArray finDwjfy() {
			JSONArray finDwjfy = prmapper.finDwjfy();
			return finDwjfy;
	}
	//<!-- 根据医疗卡号 查询所有未交费的药单 -->
	public  JSONArray medfindwjf(String mecard_number ) {
		JSONArray medfindwjf = prmapper.medfindwjf(mecard_number);
		return medfindwjf;
	}
	
	//<!-- 根据医疗卡号 查询以交费的药单 -->
	public  JSONArray medfindwjfy(String mecard_number ) {
			JSONArray medfindwjfy = prmapper.medfindwjfy(mecard_number);
			return medfindwjfy;
	}
	
	
	//根据药方主表id查询详表药品信息 
	public  JSONArray idFindxq(Integer prescription_id) {
		JSONArray idFindxq = prmapper.idFindxq(prescription_id);
		return idFindxq;
	}
	
	//查询所有未交费的体检
	public  JSONArray findTjwjf() {
			JSONArray findTjwjf = tjmapper.findTjwjf();
			return findTjwjf;
	}
	/*<!--  根据体检主表id查询体检详情项目-->*/
	
	public JSONArray idTijian(Integer medical_notice_id) {
		JSONArray idTijian = tjmapper.idTijian(medical_notice_id);
		return idTijian;
	}
	
	//新增治疗项目收费记录//同时修改未交费的状态
	public void addylxm(Integer outpatient_id,Integer
			cure_cost_id,BigDecimal charge_xmjze,BigDecimal 
			xmprescription_ss,BigDecimal xmprescription_zl,
			BigDecimal xmprescription_yh,BigDecimal xmprescription_ys,String userName) {
		CureCostPx cureCostPx = curedao.findById(cure_cost_id).get();//通过医疗项目ID得到实体
		cureCostPx.setSfjf(0);//改成0变成已收费状态
		curedao.save(cureCostPx);
		
		RegisteredPx registeredPx = regdao.findById(outpatient_id).get();//通过门诊号得到挂号实体
		MzcostDetailsRecordPx  mzcost=new  MzcostDetailsRecordPx();
		mzcost.setChargeXmdate(new Date());//收费时间
		mzcost.setChargeXmjze(charge_xmjze);
		mzcost.setCureCostPx(cureCostPx);
		mzcost.setRegisteredPx(registeredPx);
		mzcost.setXmprescriptionSs(xmprescription_ss);//实收
		mzcost.setXmprescriptionYh(xmprescription_yh);//优惠
		mzcost.setXmprescriptionYs(xmprescription_ys);//应收
		mzcost.setXmprescriptionZl(xmprescription_zl);//找零
		
		mzcost.setXmsfr(userName);
		mdao.save(mzcost);
	}
	
	//新增药品收费记录//同时收完费就是修改药方主表未交费的状态
	public String  addyfsfjl(Integer outpatient_id,Integer prescription_id,
			BigDecimal prescription_ys,BigDecimal prescription_ss,
			BigDecimal prescription_zl,BigDecimal prescription_yh,String prescription_name,String userName){
			PrescriptionPx prescriptionPx = pdao.findById(prescription_id).get();
			prescriptionPx.setPrescriptionState(1);//1代表已缴费
			pdao.save(prescriptionPx);
			RegisteredPx registeredPx = regdao.findById(outpatient_id).get();//通过门诊号得到挂号实体
			if(registeredPx!=null) {
				YfChangerPx  yf=new YfChangerPx();
				yf.setKfys(prescription_name);
				yf.setPrescriptionPx(prescriptionPx);//药方实体
				yf.setPrescriptionSs(prescription_ss);
				yf.setPrescriptionYh(prescription_yh);
				yf.setPrescriptionYs(prescription_ys);
				yf.setPrescriptionZl(prescription_zl);
				yf.setRegisteredPx(registeredPx);//通过门诊号的到挂号实体传入
				yf.setYfChangerDate(new Date());
				yf.setYfsfr(userName);
				yfdao.save(yf);
				return "1";
			}else {
				return "0";
			}
			
			
	}
	
	/*//新增体检收费记录 //同时修改缴费状态
	public String addtjsfjl(Integer outpatient_id,Integer medical_notice_id,
			BigDecimal tjsf_zje,BigDecimal tj_ys,
			BigDecimal tj_ss,BigDecimal tj_yh,BigDecimal tj_zl){
		
		RegisteredPx registeredPx = regdao.findById(outpatient_id).get();//通过门诊号得到挂号实体
		MedicalNoticePx medicalNoticePx = mndao.findById(medical_notice_id).get();
		medicalNoticePx.setMedicalNoticeState(0);//1表示已缴费
		mndao.save(medicalNoticePx);
		if(registeredPx!=null) {
				TjsfjlbTbPx tj=new TjsfjlbTbPx();
				tj.setRegisteredPx(registeredPx);
				tj.setMedicalNoticePx(medicalNoticePx);
				tj.setTjdate(new Date());
				tj.setTjsfr("华罗庚");
				tj.setTjsfZje(tjsf_zje);
				tj.setTjSs(tj_ss);
				tj.setTjYh(tj_yh);
				tj.setTjYs(tj_ys);
				tj.setTjZl(tj_zl);
				tjdao.save(tj);
				return "1";
		}else {
				return "0";
		}
		
	}
	*/
	//新增体检收费记录 //同时修改缴费状态
	public void addtjsfjl(Integer examine_id,
			BigDecimal tjsf_zje,BigDecimal tj_ys,
			BigDecimal tj_ss,BigDecimal tj_yh,BigDecimal tj_zl,String userName){
			Examine examine = examdao.findById(examine_id).get();
				examine.setExamineState("1");
				examdao.save(examine);
				TjsfjlbTbPx tj=new TjsfjlbTbPx();
				tj.setExamine(examine);
				tj.setTjdate(new Date());
				tj.setTjsfr(userName);
				tj.setTjsfZje(tjsf_zje);
				tj.setTjSs(tj_ss);
				tj.setTjYh(tj_yh);
				tj.setTjYs(tj_ys);
				tj.setTjZl(tj_zl);
				tjdao.save(tj);
		
		
	}
	
	//新增住院通知记录
	public void addhos(Integer mzcard_id,String userName) {
		HospitalNotice hos=new HospitalNotice();
		hos.setHospitalDate(new Date());
		
		hos.setZytzName(userName);
		MedicalCardPx medicalCardPx = ylkdao.findById(mzcard_id).get();
		hos.setMedicalCardPx(medicalCardPx);
		hdao.save(hos);
	}
	
	
	
	//<!-- 查询所有药方药方收费记录 -->
	public JSONArray findyfchanger() {
		JSONArray findyfchanger = yfmapper.findyfchanger();
		return findyfchanger;
	}
	//<!-- 根据医疗卡号查询药方药方收费记录 -->
	public JSONArray medfindyfchanger(String mecard_number) {
		JSONArray medfindyfchanger = yfmapper.medfindyfchanger(mecard_number);
		return medfindyfchanger;
	}
	
	
	//查询所有体检缴费记录
	public  JSONArray  findtjsfjl() {
		JSONArray findtjsfjl = tjsfmapper.findtjsfjl();
		return findtjsfjl;
	}
	
	//根据医疗卡号查询所有体检缴费记录
		public  JSONArray  medfindtjsfjl(Integer examine_id) {
			JSONArray medfindtjsfjl = tjsfmapper.medfindtjsfjl(examine_id);
			return medfindtjsfjl;
		}
	
	//查询所有医疗项目缴费记录
	public JSONArray findxmsfjl() {
		JSONArray findxmsfjl = xmmapper.findxmsfjl();
		return findxmsfjl;
	}
	//根据医疗卡号查询所有医疗项目缴费记录
	public JSONArray mefindxmsfjl(String mecard_number) {
		JSONArray mefindxmsfjl = xmmapper.mefindxmsfjl(mecard_number);
		return mefindxmsfjl;
	}
	
	
	///*<!-- 根据药方主表id查询寻该条的收费情况打印票据 -->*/
	public JSONArray  ypiddapj(Integer prescription_id) {
		
		JSONArray iddapj = prmapper.ypiddapj(prescription_id);
		return iddapj;
	}
	
	/*<!--  打印体检收费票据-->*/
	public  JSONArray tjidDapj(Integer examine_id) {
		JSONArray tjidDapj = em.TjidDapj(examine_id);
		return tjidDapj;
	}
	
	//<!-- 根据门诊项目费用主表查询项目收费情况 -->
	public  JSONArray xmidDpj(Integer cure_cost_id) {
		JSONArray xmidDpj = cmapper.xmidDpj(cure_cost_id);
		return xmidDpj;
	}
	
	//<!-- 根据门诊项目费用主表查询项目收费情况 -->
	public  JSONArray djdl() {
			JSONArray djdl = emmpar.djdl();
			return djdl;
	}
	
	//查询未交费的体检项目单
	public  JSONArray djdly() {
				JSONArray djdly = emmpar.djdly();
				return djdly;
	}
	
	//根据医疗卡号查询未交费的体检单
	public JSONArray carddjdl(Integer examine_id) {
			JSONArray carddjdl = emmpar.carddjdl(examine_id);
			return carddjdl;
	}
	//根据体检号查询以交费的体检单
	public JSONArray carddjdly(String mecard_number) {
			JSONArray carddjdly =emmpar.carddjdly(mecard_number);
			return carddjdly;
	}
	
	
	 //根据体检登记主表id查询详表 -->
	public JSONArray idtjdl(Integer examine_id) {
		JSONArray idtjdl = emmpar.idtjdl(examine_id);
		return idtjdl;
	}
	
	//查询所有需要退费的药单记录
	public JSONArray yaofangtuifei() {
		JSONArray yaofangtuifei = tfjlmp.yaofangtuifei();
		return yaofangtuifei;
	}
	
	//退药药单查询详情
	public JSONArray tycxq(Integer return_id) {
		 JSONArray tycxq = tfjlmp.tycxq(return_id);
		return tycxq;
	}
	
	
	//<!-- 门诊查询体检结果查询 -->
	public JSONArray mztjjg() {
			JSONArray mztjjg = em.mztjjg();
			return mztjjg;
	}
	//<!-- 根据医疗卡号查询体检结果查询 -->
	public  JSONArray mztjjgYl(String mecard_number) {
			JSONArray mztjjgYl = em.mztjjgYl(mecard_number);
			return mztjjgYl;
	}
	
	//<!-- 根据体检号查询体检医生和结果 -->
	public JSONArray tjhcJg(Integer examine_id) {
			JSONArray tjhcJg = em.tjhcJg(examine_id);
			return tjhcJg;
	}
	
	//<!-- 根据体检号查询体检医生和结果 二-->
	public JSONArray tjhcJgEr(Integer examine_id) {
			JSONArray tjhcJgEr = em.tjhcJgEr(examine_id);
			return tjhcJgEr;
	}
	
	//查询所有班次
	public JSONArray BcAll() {
			JSONArray bcAll = arrmp.BcAll();
			return bcAll;
	}
	
	//查询所有医生
	public  JSONArray  YsAll(){
		JSONArray ysAll = ump.YsAll();
		return ysAll;
	}
	
	//新增排班记录
	public void  addPb(Integer departments_id,Integer arrange_classes_id,Integer user_id,String sj){
		ArrangeClassPx  arr=new ArrangeClassPx();
		Date datee=new Date(sj);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(datee);
		
		
		arr.setArrangeClassDate(dateString);
		arr.setPbdate(new Date());
		User user = userdao.findById(user_id).get();
		DepartmentsPx departmentsPx = ksdao.findById(departments_id).get();
		ArrangeClass arrangeClass = adao.findById(arrange_classes_id).get();
		arr.setUser(user);
		arr.setDepartmentsPx(departmentsPx);
		arr.setArrangeClass(arrangeClass);
		arrdao.save(arr);
	}
	
	//<!--根据用户id和排班时间查询用户 是否已经排班 -->
	public  JSONArray  ScheduLing(Integer user_id ,String sj){
		JSONArray scheduLing = arrmapper.ScheduLing(user_id,sj);
		return scheduLing;
	}
	
	//<!--根据科室编号查询改科室下的所有医生 -->
	public  JSONArray  KscYs(Integer departments_id) {
		JSONArray kscYs = arrmapper.KscYs(departments_id);
		return 	kscYs;
		
	}
	
	//查询所有护士
	public JSONArray HsAll() {
		JSONArray hsAll = ump.HsAll();
		return hsAll;
	}
	
	//查询所有排班记录
	public JSONArray PbAll(String user_name) {
		if(user_name!=null) {
			if(user_name.trim().equals("")) {
				user_name=null;
			}
		}
		JSONArray pbAll = arrmapper.PbAll(user_name);
		return pbAll;
	}
	
	//门诊查询所有科室
	public  JSONArray  findMzks() {
			JSONArray findMzks = deptmapper.findMzks();
			return findMzks;
	}
	
	
	//<!-- 根据系统时间查询门诊部上早班的医生 -->
	public JSONArray mzYszb(Integer departments_id) {
		JSONArray mzYszb = arrmapper.mzYszb(departments_id);
		return mzYszb;
	}
	//<!-- 根据系统时间查询门诊部上中班的医生 -->
	public JSONArray mzYshb(Integer departments_id) {
		JSONArray mzYshb = arrmapper.mzYshb(departments_id);
		return mzYshb;
	}
	//<!-- 根据系统时间查询门诊部上晚班的医生 -->
	public JSONArray mzYswb(Integer departments_id) {
		JSONArray mzYswb = arrmapper.mzYswb(departments_id);
		return mzYswb;
	};
	
	//<!-- 根据系统时间查询门诊部上夜班的医生 -->
	public JSONArray mzYsyb(Integer departments_id) {
		JSONArray mzYsyb = arrmapper.mzYsyb(departments_id);
		return mzYsyb;
	};
	
	
	//<!-- 根据系统时间查询门诊部上早班的护士 -->
	public JSONArray mzHszb(Integer departments_id) {
		JSONArray mzHszb = arrmapper.mzHszb(departments_id);
		return mzHszb;
	}
	//<!-- 根据系统时间查询门诊部上中班的护士-->
	public JSONArray mzHshb(Integer departments_id) {
		JSONArray mzHshb = arrmapper.mzHshb(departments_id);
		return mzHshb;
	}
	//<!-- 根据系统时间查询门诊部上晚班的护士 -->
	public JSONArray mzHswb(Integer departments_id) {
		JSONArray mzHswb = arrmapper.mzHswb(departments_id);
		return mzHswb;
	};
	
	//<!-- 根据系统时间查询门诊部上夜班的护士 -->
	public JSONArray mzHsyb(Integer departments_id) {
		JSONArray mzHsyb = arrmapper.mzHsyb(departments_id);
		return mzHsyb;
	};
	
		
		//<!-- 根据上班时间查询上班医生护士 -->
		public  JSONArray sbShiJian(String arrange_class_date) {
			if(arrange_class_date!=null) {
				if(arrange_class_date.trim().equals("")) {
					arrange_class_date=null;
				}
			}
			JSONArray sbShiJian = arrmapper.sbShiJian(arrange_class_date);
			return sbShiJian;
		}
		
		// <!-- 统计每年门诊处 每年的利润-->
		public JSONArray  mzCounter(Integer datesj) {
			return arrmp.mzCounter(datesj);
		}
	
		/*public JSONArray  mzCounter( ) {
			return arrmp.mzCounter();
		}*/
	
		//<!-- 统计每年住院处接诊的人数-->
		public JSONArray zyCount() {
			JSONArray zyCount = arrmp.zyCount();
			return zyCount;
		}
		
		//<!--根据用户id查角色  -->
		public  JSONArray  jueSe(Integer user_id) {
			JSONArray jueSe = ump.jueSe(user_id);
			return jueSe;
		}
		
		
		
		//<!--门诊科室新增查询是否有相同的科室  -->
		public  JSONArray  mzaddks( String departments_name) {
			JSONArray mzaddks = deptmapper.mzaddks(departments_name);
			return mzaddks;
		}
		
		//<!--住院科室新增查询是否有相同的科室  -->
		public  JSONArray  zyaddks (String departments_name) {
			JSONArray zyaddks = deptmapper.zyaddks(departments_name);
			return zyaddks;
		}
		
		//新增科室
		public void addks(String ksmc,Integer kslb){
			DepartmentsPx dept=new DepartmentsPx();
			dept.setDepartmentsName(ksmc);
			
			dept.setDepartmentslb(kslb);
			ksdao.save(dept);
		}
		//<!--新增医疗项目查询是否有相同 -->
		public JSONArray ymAdd(String cure_name) {
			JSONArray ymAdd = curemp.ymAdd(cure_name);
			return ymAdd;
		}
		//新增医疗项目
		public  void addylxm(String xmmc,BigDecimal xmje) {
			CurePx cure=new CurePx();
			cure.setCureJe(xmje);
			cure.setCureName(xmmc);
			curepsdao.save(cure);	
		}
		//查询所有科室
		public JSONArray findks(String departments_name) {
			if(departments_name!=null) {
				if(departments_name.trim().equals("")) {
					departments_name=null;
				}
			}
			JSONArray findks=deptmapper.findks(departments_name);
			return findks;
		}
		
		//<!-- 新增体检项目查询有没有相同的 -->
		public  JSONArray  xzTjxmCx(String  examine_item_name) {
			JSONArray xzTjxmCx = em.xzTjxmCx(examine_item_name);
			return xzTjxmCx;
		}
		
		//新增体检医疗项目
		public  void addtjxm(String examine_item_name,BigDecimal tjxmje) {
			ExamineItem  ex=new ExamineItem();
			ex.setExamineItemName(examine_item_name);
			ex.setExamineItemPrice(tjxmje);
			edao.save(ex);	
		}
		//单独查询急诊
		public  JSONArray cxjz() {
				JSONArray cxjz = gmp.cxjz();
				return cxjz;
		}
		
}
